package com.erhuogo.interceptor;

import org.apache.struts2.ServletActionContext;

import com.erhuogo.entity.Member;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

/**
 * 权限拦截器
 * 
 * @author aibinxiao
 * @date 2016年10月25日 上午10:20:10
 */
public class PrivilegeInterceptor extends MethodFilterInterceptor {
	private static final long serialVersionUID = 8582364465776433905L;

	@Override
	protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
		// 判断是否登录,如果登录,放行,没有登录,跳转到登录页面.
		Member member = (Member) ServletActionContext.getRequest().getSession().getAttribute("existMember");
		if (member != null) {
			// 已经登录过
			return actionInvocation.invoke();
		} else {
			// 跳转到登录页面:
			ActionSupport support = (ActionSupport) actionInvocation.getAction();
			support.addActionError("您还没有登录!没有权限访问!");
			return ActionSupport.LOGIN;
		}
	}

}
